home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FWiXprefs.c
-
- Contains: Preferences dialog and initialization.
-
- Version: 1.0
-
- Written by: Jay Lloyd
-
- Copyright: © 1996-1999 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: Jay Lloyd
-
- Other Contact:
-
- Technology: FireWire
-
- Writers:
-
- (DCB) Clinton Bauder
- (jkl) Jay Lloyd
-
- Change History (most recent first):
-
- <FW11> 4/8/99 jkl More interface cleanup.
- <FW10> 2/2/99 DCB Fix for new MI headers.
- <FW9> 12/19/98 DCB More cleanup for SDK.
- <8> 1/15/98 jkl Update for new headers.
- <FW7> 6/19/97 jkl Added a preference for saving the icon view.
- <FW6> 6/10/97 jkl Updated qd global name.
- <FW5> 5/27/97 jkl Corrected a problem with the receive folder being created that
- would cause a receive folder location other than the default to
- not get saved.
- <FW4> 5/7/97 jkl Updated data structure names.
- <FW3> 4/29/97 jkl Fixed my bbs initials to not conflict with Jim Luther.
- <FW2> 4/29/97 jkl Added a call to Handle update event to the preferences dialog
- event filter routine.
- <FW1> 3/18/97 jkl first checked in
- */
-
- #include <Files.h>
- #include <Dialogs.h>
- #include <Sound.h>
- #include <Resources.h>
- #include <StandardFile.h>
- #include <Script.h>
- #include <Aliases.h>
- #include <Folders.h>
- #include <TextUtils.h>
- #include <QuickDraw.h>
- #include <TextEdit.h>
- #include <Fonts.h>
- #if !ETO_Build
- #include <ControlDefinitions.h>
- #endif
-
- #include "FWiX.h"
- #include "FWiXmain.h"
- #include "FWiXdrag.h"
- #include "FWiXprefs.h"
-
- static FSSpec gDeskFolderSpec;
- static Str255 gSelectString = "\pSelect";
- static Str31 gDesktopFName = "\pDesktop";
- static FSSpec gSelectSpec;
-
- extern FWXAppDataPtr gpFWXAppData;
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandlePrefsDialog
- //
- // Handle the Preferences dialog.
- //
- OSErr HandlePrefsDialog (void)
- {
- DialogPtr pDlog;
- UserItemUPP pUserDefProc;
- ModalFilterUPP pModalFilterProc;
- Ptr pTemp;
- Handle item;
- Rect box;
- SInt16 itemHit;
- OSErr err = noErr;
-
- pUserDefProc = NewUserItemProc(DrawDefaultButton);
- if (pUserDefProc == nil)
- return memFullErr;
-
- pModalFilterProc = NewModalFilterProc(HandlePrefsEventFilter);
- if (pModalFilterProc == nil)
- return memFullErr;
-
- // set received items folder name
- ParamText(gpFWXAppData->fwixReceiveFolder.name, "\p", "\p", "\p");
-
- pDlog = GetNewDialog(kPrefsDlogID, nil, (WindowPtr) -1);
- if (pDlog != nil) {
- // get handle to default button user item and replace with draw proc
- GetDialogItem(pDlog, kDefaultUserItem, &itemHit, &item, &box);
- SetDialogItem(pDlog, kDefaultUserItem, itemHit,
- (Handle) pUserDefProc, &box);
- SetupDialogPrefs(pDlog);
- HiliteMenu(0); // unhilight menu title
-
- // JKL *** select sound name
- ShowWindow(pDlog);
- } else
- err = ResError();
-
- if (err == noErr)
- {
- do
- {
- ModalDialog(pModalFilterProc, &itemHit);
- HandlePrefsDialogEvent(pDlog, itemHit);
- } while ((itemHit != kOKButton) && (itemHit != kCancelButton));
-
- HideWindow(pDlog);
- if (itemHit == kOKButton)
- err = UpdateDialogPrefs(pDlog);
-
- // clean up dialog memory allocations
- pTemp = (Ptr) GetWRefCon(pDlog);
- DisposePtr(pTemp);
- DisposeRoutineDescriptor(pModalFilterProc);
- DisposeRoutineDescriptor(pUserDefProc);
- DisposeDialog(pDlog);
- }
- return err;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // HandlePrefsDialogEvent
- //
- // Handle mouseDowns in dialog items
- //
- static void HandlePrefsDialogEvent(
- DialogPtr pDlog,
- SInt16 itemHit)
- {
- Str255 s;
- PopupPrivateDataHandle hPopup;
- RgnHandle hRgn;
- WindowPtr curPort;
- Handle itemHandle;
- FSSpecPtr pDropFolder;
- Rect box;
- StandardFileReply reply;
- SInt16 itemType;
- SInt16 curVal;
- SInt16 whichSound;
- SInt16 curAttributes;
-
- if ((itemHit >= kFlashBox) && (itemHit <= kOpenBox))
- {
- GetDialogItem(pDlog, itemHit, &itemType, &itemHandle, &box);
- curVal = GetControlValue((ControlHandle) itemHandle);
- SetControlValue((ControlHandle) itemHandle, 1 - curVal);
-
- if (itemHit == kSoundBox)
- {
- GetDialogItem(pDlog, kSoundPopup, &itemType, &itemHandle, &box);
- hPopup = (PopupPrivateDataHandle) (**((ControlHandle) itemHandle)).contrlData;
-
- if (curVal == 0)
- EnableItem((**hPopup).mHandle, 0);
- else
- DisableItem((**hPopup).mHandle, 0);
-
- hRgn = NewRgn();
- if (hRgn != nil)
- {
- RectRgn(hRgn, &(**((ControlHandle) itemHandle)).contrlRect);
- UpdateControls(pDlog, hRgn);
- DisposeRgn(hRgn);
- }
- else
- DrawControls(pDlog);
- }
- }
- else if ((itemHit >= kCancelRadio) && (itemHit <= kOverwriteRadio))
- {
- GetDialogItem(pDlog, kCancelRadio, &itemType, &itemHandle, &box);
- if (itemHit == kCancelRadio)
- SetControlValue((ControlHandle) itemHandle, 1);
- else
- SetControlValue((ControlHandle) itemHandle, 0);
-
- GetDialogItem(pDlog, kRenameRadio, &itemType, &itemHandle, &box);
- if (itemHit == kRenameRadio)
- SetControlValue((ControlHandle) itemHandle, 1);
- else
- SetControlValue((ControlHandle) itemHandle, 0);
-
- GetDialogItem(pDlog, kOverwriteRadio, &itemType, &itemHandle, &box);
- if (itemHit == kOverwriteRadio)
- SetControlValue((ControlHandle) itemHandle, 1);
- else
- SetControlValue((ControlHandle) itemHandle, 0);
- }
- else if (itemHit == kSoundPopup)
- {
- // if the play sound box is checked, play the sound
- GetDialogItem(pDlog, kSoundBox, &itemType, &itemHandle, &box);
- curVal = GetControlValue((ControlHandle) itemHandle);
- if (curVal == 1)
- {
- GetDialogItem(pDlog, kSoundPopup, &itemType, &itemHandle, &box);
- whichSound = GetControlValue((ControlHandle) itemHandle);
- hPopup = (PopupPrivateDataHandle) (**((ControlHandle) itemHandle)).contrlData;
- GetMenuItemText((**hPopup).mHandle, whichSound, s);
- itemHandle = GetNamedResource('snd ', s);
- if (itemHandle != nil)
- {
- curAttributes = GetResAttrs(itemHandle);
- if (curAttributes & resPurgeable)
- HNoPurge(itemHandle);
- SndPlay(nil, (SndListHandle) itemHandle, false);
- SetResAttrs(itemHandle, curAttributes);
- ReleaseResource(itemHandle);
- }
- }
- }
- else if (itemHit == kDropButton)
- {
- GetDropFolder(&reply);
- if (reply.sfGood) {
- pDropFolder = (FSSpecPtr) GetWRefCon(pDlog);
- FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, pDropFolder);
- ParamText(pDropFolder->name, "\p", "\p", "\p");
-
- GetPort(&curPort);
- SetPort(pDlog);
- InvalRect(&(pDlog->portRect));
- SetPort(curPort);
- }
- }
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // GetDeskFolderSpec
- //
- // Create FSSpec for Desktop folder
- //
- static OSErr GetDeskFolderSpec(
- FSSpec *pFileSpec)
- {
- OSErr err;
-
- pFileSpec->name[0] = '\0';
- err = FindFolder(kOnSystemDisk, kDesktopFolderType, kDontCreateFolder,
- &pFileSpec->vRefNum, &pFileSpec->parID);
- if (err)
- return err;
-
- err = FSMakeFSSpec(pFileSpec->vRefNum, pFileSpec->parID, pFileSpec->name,
- pFileSpec);
- return err;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // GetDropFolder
- //
- // Select a fwix receive folder
- //
- static OSErr GetDropFolder (
- StandardFileReply *reply )
- {
- FileFilterYDUPP pMyFileFilter;
- DlgHookYDUPP pMyDlogHook;
- Point where = {-1,-1};
- OSErr err = noErr;
-
- pMyFileFilter = NewFileFilterYDProc(FilterAllFiles);
- if (pMyFileFilter == nil)
- return memFullErr;
- pMyDlogHook = NewDlgHookYDProc(DialogHook);
- if (pMyDlogHook == nil)
- return memFullErr;
- GetDeskFolderSpec(&gDeskFolderSpec);
-
- CustomGetFile(pMyFileFilter, -1, nil, reply, kCustomGetFileResID,
- where, pMyDlogHook, nil, nil, nil, reply);
-
- DisposeRoutineDescriptor(pMyDlogHook);
- DisposeRoutineDescriptor(pMyFileFilter);
- return err;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // DialogHook
- //
- // Handle custom get file dialog actions.
- //
- static pascal SInt16 DialogHook (
- SInt16 item,
- DialogPtr pDlog,
- Ptr pMyData)
- {
- UserItemUPP pUserDefProc;
- StandardFileReply *reply;
- FSSpec curSpec;
- OSType refCon;
- Handle hDlogItem;
- Rect box;
- SInt16 itemHit;
- static FSSpec lastSpec;
-
- refCon = GetWRefCon(pDlog);
- if (refCon != sfMainDialogRefCon)
- return item;
-
- reply = (StandardFileReply *) pMyData;
-
- switch (item)
- {
- case sfHookFirstCall:
- lastSpec.vRefNum = -9999; // init to ridiculous valuesx
- pUserDefProc = NewUserItemProc(DrawUserSelection);
- GetDialogItem(pDlog, kCustomGetUserItem, &itemHit, &hDlogItem, &box);
- SetDialogItem(pDlog, kCustomGetUserItem, itemHit, (Handle) pUserDefProc, &box);
- reply->sfFile = gpFWXAppData->fwixReceiveFolder;
- item = sfHookChangeSelection;
- break;
-
- case sfHookLastCall:
- GetDialogItem(pDlog, kCustomGetUserItem, &itemHit, &hDlogItem, &box);
- DisposeRoutineDescriptor((UniversalProcPtr) itemHit);
- break;
-
- case sfHookNullEvent:
- if (!SameFile(&reply->sfFile, &lastSpec))
- {
- curSpec = reply->sfFile;
- FSMakeFSSpec(curSpec.vRefNum, curSpec.parID, curSpec.name, &curSpec);
- GetDialogItem(pDlog, kCustomGetUserItem, &itemHit, &hDlogItem, &box);
- InvalRect(&box);
- //SetSelectButtonName(&curSpec, pDlog);
- lastSpec = reply->sfFile;
- gSelectSpec = curSpec;
- }
- break;
-
- case kSelectItem:
- item = sfItemOpenButton;
- break;
- }
- return item;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // SameFile
- //
- // Checks two file specs to see if they are equal
- //
- static Boolean SameFile (
- FSSpec *spec1,
- FSSpec *spec2)
- {
- if (spec1->vRefNum != spec2->vRefNum)
- return false;
- if (spec1->parID != spec2->parID)
- return false;
- if (!EqualString( spec1->name, spec2->name, false, true))
- return false;
- return true;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // SetSelectButtonName
- //
- // This routine gets the "Select" button from the CustomGetFile dialog and
- // the filename string from the FSSpec parameter. It set the buttons name
- // to Select “filename”, truncating the filemane if needed. The button is
- // dimmed if kCanSelectDesktop is false and the FSSpec is desktop folder.
- static void SetSelectButtonName (
- FSSpec *spec,
- DialogPtr theDlg)
- {
- HParamBlockRec pb;
- Handle iHndl;
- Rect iRect;
- Str63 selNameTrunc = "\p";
- Str255 btnName = "\p";
- SInt16 iType;
- SInt16 btnWidth;
- OSErr err;
- Boolean hilited = true;
-
- pb.volumeParam.ioVRefNum = spec->vRefNum;
- pb.volumeParam.ioNamePtr = nil;
- pb.volumeParam.ioVolIndex = 0; // use ioVRefNum only
- err = PBHGetVInfoSync(&pb);
- if (err == noErr) {
- if ((pb.volumeParam.ioVAtrb & 0x0080) != 0) {
- // volume locked by hardware
- hilited = false;
- } else if ((pb.volumeParam.ioVAtrb & 0x8000) != 0) {
- // volume locked by software
- hilited = false;
- }
- }
-
- if (SameFile(spec, &gDeskFolderSpec)) {
- AppendStrToStr(selNameTrunc, gDesktopFName, 63);
- hilited = kCanSelectDesktop;
- } else
- AppendStrToStr( selNameTrunc, spec->name, 63 ) ;
-
-
- GetDItem(theDlg,kSelectItem,&iType,&iHndl,&iRect);
-
- // truncate select name to fit in button
- btnWidth = iRect.right - iRect.left;
- btnWidth -= StringWidth(gSelectString);
- btnWidth -= StringWidth("\p “” ");
- TruncString(btnWidth, selNameTrunc, smTruncMiddle);
-
- // build button name string
- AppendStrToStr( btnName, gSelectString, 255 ) ;
- AppendStrToStr( btnName, "\p “", 255) ;
- AppendStrToStr( btnName, selNameTrunc, 255) ;
- AppendStrToStr( btnName, "\p”", 255) ;
-
- SetCTitle((ControlRef)iHndl, btnName);
-
- if (hilited)
- HiliteControl((ControlRef)iHndl,0);
- else
- HiliteControl((ControlRef)iHndl,255);
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // AppendStrToStr
- //
- // Concat two strings.
- //
- static void AppendStrToStr (
- StringPtr dst,
- StringPtr src,
- UInt8 maxDstLen)
- {
- short offset = dst[0]+1;
- short size = src[0];
-
- if ( dst[0] + src[0] > maxDstLen) // make sure were not too big
- size = maxDstLen - dst[0]; // you should return a warning here
- BlockMove(src+1, dst+offset, size);
- dst[0] += size;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // MyFilterAllFiles
- //
- // Removes all files from dialog box, only get directories and volumes.
- //
- static pascal Boolean FilterAllFiles (
- CInfoPBPtr pb,
- Ptr pMyData)
- {
- if (pb->hFileInfo.ioFlAttrib & ioDirMask)
- return false;
- return true;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // UpdateDialogPrefs
- //
- // After pressing OK, update settings
- //
- static OSErr UpdateDialogPrefs (
- DialogPtr pDlog)
- {
- Handle itemHandle;
- PopupPrivateDataHandle hPopup;
- FSSpecPtr pNewDropFolder;
- WindowDataPtr pWinData;
- RecvNodePtr pRecvNode;
- CurFileInfoPtr pTxInfo;
- Str255 s;
- Rect box;
- UInt32 notifyAndConflictPrefs;
- SInt16 itemType;
- SInt16 whichSound;
- OSErr err;
-
- notifyAndConflictPrefs = 0;
-
- // Get checkbox values
- GetDialogItem(pDlog, kFlashBox, &itemType, &itemHandle, &box);
- if (GetControlValue((ControlHandle) itemHandle))
- notifyAndConflictPrefs |= kNotifyFlash;
-
- GetDialogItem(pDlog, kAlertBox, &itemType, &itemHandle, &box);
- if (GetControlValue((ControlHandle) itemHandle))
- notifyAndConflictPrefs |= kNotifyAlert;
-
- GetDialogItem(pDlog, kSoundBox, &itemType, &itemHandle, &box);
- if (GetControlValue((ControlHandle) itemHandle))
- notifyAndConflictPrefs |= kNotifySound;
-
- GetDialogItem(pDlog, kOpenBox, &itemType, &itemHandle, &box);
- if (GetControlValue((ControlHandle) itemHandle))
- notifyAndConflictPrefs |= kNotifyOpen;
-
- // Get radio box values
- GetDialogItem(pDlog, kCancelRadio, &itemType, &itemHandle, &box);
- if (GetControlValue((ControlHandle) itemHandle))
- notifyAndConflictPrefs |= kConflictCancel;
-
- GetDialogItem(pDlog, kRenameRadio, &itemType, &itemHandle, &box);
- if (GetControlValue((ControlHandle) itemHandle))
- notifyAndConflictPrefs |= kConflictRename;
-
- GetDialogItem(pDlog, kOverwriteRadio, &itemType, &itemHandle, &box);
- if (GetControlValue((ControlHandle) itemHandle))
- notifyAndConflictPrefs |= kConflictOverwrite;
-
- // Update globals and resource
- gpFWXAppData->fwixPrefs &= kIconView;
- gpFWXAppData->fwixPrefs |= notifyAndConflictPrefs;
-
- // get notify sound name
- GetDialogItem(pDlog, kSoundPopup, &itemType, &itemHandle, &box);
- whichSound = GetControlValue((ControlHandle) itemHandle);
- hPopup = (PopupPrivateDataHandle) (**((ControlHandle) itemHandle)).contrlData;
- GetMenuItemText((**hPopup).mHandle, whichSound, s);
- BlockMove(s, gpFWXAppData->fwixNotifySound, s[0] + 1);
-
- // get drop folder and update open drop menu item and receive node records dirID
- pNewDropFolder = (FSSpecPtr) GetWRefCon(pDlog);
- gpFWXAppData->fwixReceiveFolder = *pNewDropFolder;
-
- // update menu item
- GetMenuItemText(GetMenuHandle(kFileMenuID), kOpenDropMenuItem, s);
- BlockMove( gpFWXAppData->fwixReceiveFolder.name + 1,
- s + 7,
- gpFWXAppData->fwixReceiveFolder.name[0]);
- s[0] = 6 + gpFWXAppData->fwixReceiveFolder.name[0] + 1;
- s[s[0]] = '”';
- SetMenuItemText(GetMenuHandle(kFileMenuID), kOpenDropMenuItem, s);
-
- // Update the drop folder in receive info records
- // Traverse the node list updating each node records dir id
- pWinData = (WindowDataPtr) GetWRefCon(gpFWXAppData->pSenderWindow);
-
- pRecvNode = pWinData->pRecvNodeList;
- while (pRecvNode != nil) {
- GetCurFileInfo(pRecvNode->nodeID, &pTxInfo, false);
- InitRecvFolder(& (pTxInfo->curDirID));
- pRecvNode = (RecvNodePtr) pRecvNode->pNextNode;
- }
-
- // update notification record
- UpdateNotification(gpFWXAppData->pNotifyRec);
-
- err = UpdatePrefsFile();
- return err;
- }
-
- OSErr UpdatePrefsFile (void)
- {
- Handle h;
- AliasHandle hAlias;
- SInt32 dirID;
- FSSpec prefsSpec;
- SInt16 vRefNum;
- SInt16 fileRefNum;
- OSErr err;
-
- // write the changes to the prefs file
- err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &vRefNum, &dirID);
- if (err != noErr)
- return err;
-
- // create the preferences file if it does not exist
- h = Get1Resource('STR ', kPrefsFileResourceID);
- if (h == nil)
- return ResError();
- DetachResource(h);
- HLock(h);
- err = FSMakeFSSpec(vRefNum, dirID, (ConstStr255Param) *h, &prefsSpec);
- HUnlock(h);
- DisposeHandle(h);
- if (err == fnfErr)
- {
- FSpCreateResFile(&prefsSpec, 'fwfx', 'pref', smSystemScript);
- err = ResError();
- if (err != noErr)
- return err;
- }
-
- fileRefNum = FSpOpenResFile(&prefsSpec, fsRdWrPerm);
- err = ResError();
- if (err == noErr)
- {
- h = Get1Resource(kPrefsResourceType, kPrefsResourceID);
- if (h != nil)
- {
- **((UInt32 **) h) = gpFWXAppData->fwixPrefs;
- ChangedResource(h);
- ReleaseResource(h);
- }
-
- h = Get1Resource('STR ', kSndPrefsResourceID);
- if (h != nil)
- {
- SetHandleSize(h, gpFWXAppData->fwixNotifySound[0] + 1);
- err = MemError();
- BlockMove(gpFWXAppData->fwixNotifySound, *h, gpFWXAppData->fwixNotifySound[0] + 1);
- ChangedResource(h);
- ReleaseResource(h);
- }
-
- h = Get1Resource(rAliasType, kDropPrefsResourceID);
- if (h != nil)
- {
- err = NewAliasMinimal(&gpFWXAppData->fwixReceiveFolder, (AliasHandle *) &hAlias);
- SetHandleSize(h, (**hAlias).aliasSize);
- BlockMove(*hAlias, *h, (**hAlias).aliasSize);
- ChangedResource(h);
- ReleaseResource(h);
- }
- CloseResFile(fileRefNum);
- FlushVol(nil, vRefNum);
- }
-
- return err;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // SetupDialogPrefs
- //
- // Initialize dialog item settings before opening
- //
- static OSErr SetupDialogPrefs (
- DialogPtr pDlog)
- {
- Handle itemHandle;
- FSSpecPtr pTempReceiveFolder;
- PopupPrivateDataHandle hPopup;
- Str255 soundText;
- Rect box;
- SInt16 itemType;
- SInt16 itemVal;
- SInt16 activeRadio;
- SInt16 numSounds;
- SInt16 soundItem;
-
- // setup check boxes
- GetDialogItem(pDlog, kFlashBox, &itemType, &itemHandle, &box);
- SetControlValue((ControlHandle) itemHandle,
- (gpFWXAppData->fwixPrefs & kNotifyFlash) ? 1 : 0);
-
- GetDialogItem(pDlog, kAlertBox, &itemType, &itemHandle, &box);
- SetControlValue((ControlHandle) itemHandle,
- (gpFWXAppData->fwixPrefs & kNotifyAlert) ? 1 : 0);
-
- GetDialogItem(pDlog, kSoundBox, &itemType, &itemHandle, &box);
- SetControlValue((ControlHandle) itemHandle,
- (gpFWXAppData->fwixPrefs & kNotifySound) ? 1 : 0);
-
- GetDialogItem(pDlog, kOpenBox, &itemType, &itemHandle, &box);
- SetControlValue((ControlHandle) itemHandle,
- (gpFWXAppData->fwixPrefs & kNotifyOpen) ? 1 : 0);
-
- // setup radio buttons, zero them all then set the preference
- GetDialogItem(pDlog, kCancelRadio, &itemType, &itemHandle, &box);
- SetControlValue((ControlHandle) itemHandle, 0);
-
- GetDialogItem(pDlog, kRenameRadio, &itemType, &itemHandle, &box);
- SetControlValue((ControlHandle) itemHandle, 0);
-
- GetDialogItem(pDlog, kOverwriteRadio, &itemType, &itemHandle, &box);
- SetControlValue((ControlHandle) itemHandle, 0);
-
- activeRadio = (gpFWXAppData->fwixPrefs & 0x0F) >> 1;
- GetDialogItem(pDlog, kCancelRadio + activeRadio, &itemType, &itemHandle, &box);
- SetControlValue((ControlHandle) itemHandle, 1);
-
- // setup the sound popup
- GetDialogItem(pDlog, kSoundPopup, &itemType, &itemHandle, &box);
- hPopup = (PopupPrivateDataHandle) (**((ControlHandle) itemHandle)).contrlData;
-
- numSounds = CountMItems((**hPopup).mHandle);
- for (soundItem = 1; soundItem < numSounds; soundItem++)
- {
- GetMenuItemText((**hPopup).mHandle, soundItem, soundText);
- if (EqualString(gpFWXAppData->fwixNotifySound, soundText, true, true))
- break;
- }
- SetControlValue((ControlHandle) itemHandle, soundItem);
-
- GetDialogItem(pDlog, kSoundBox, &itemType, &itemHandle, &box);
- itemVal = GetControlValue((ControlHandle) itemHandle);
- if (itemVal == 1)
- EnableItem((**hPopup).mHandle, 0);
- else
- DisableItem((**hPopup).mHandle, 0);
-
- // setup receive folder fsspec, stored in refCon until done
- pTempReceiveFolder = (FSSpecPtr) NewPtr(sizeof(FSSpec));
- if (pTempReceiveFolder == nil)
- return memFullErr;
-
- *pTempReceiveFolder = gpFWXAppData->fwixReceiveFolder;
- SetWRefCon(pDlog, (SInt32) pTempReceiveFolder);
-
- return noErr;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // HandlePrefsEventFilter
- //
- // Handles modal dialog filter
- //
- static pascal Boolean HandlePrefsEventFilter(
- DialogPtr pDlog,
- EventRecord *pEvent,
- SInt16 *itemHit)
- {
- Handle item;
- Rect box;
- UInt32 finalTicks;
- SInt16 itemType;
- UInt8 key;
- Boolean handledIt;
-
- handledIt = false;
-
- switch (pEvent->what)
- {
- case keyDown:
- key = pEvent->message & charCodeMask;
-
- if (key == kReturnKey || key == kEnterKey)
- {
- GetDialogItem(pDlog, kOKButton, &itemType, &item, &box);
- HiliteControl((ControlHandle) item, kControlButtonPart);
- Delay(8, &finalTicks);
- HiliteControl((ControlHandle) item, 0);
- handledIt = true;
- *itemHit = kOKButton;
- }
- else if (((pEvent->modifiers & cmdKey) && (key == kPeriodKey)) || (key == kEscapeKey))
- {
- GetDialogItem(pDlog, kCancelButton, &itemType, &item, &box);
- HiliteControl((ControlHandle) item, kControlButtonPart);
- Delay(8, &finalTicks);
- HiliteControl((ControlHandle) item, 0);
- handledIt = true;
- *itemHit = kCancelButton;
- }
- break;
-
- case nullEvent:
- HandleIdle();
- break;
-
- case updateEvt:
- HandleUpdateEvent(pEvent);
- break;
-
- case activateEvt:
- break;
- }
- return handledIt;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // DrawUserSelection
- //
- // Draws the selected folder text.
- //
- static pascal void DrawUserSelection(
- WindowPtr theWindow,
- SInt16 itemNo)
- {
- WindowPtr curPort;
- Handle item;
- Rect box;
- SInt32 sLength = 47;
- Str255 s = "Click the Select button to select the folder: “";
- SInt16 itemType;
- SInt16 oldFont, oldSize;
-
- GetDialogItem(theWindow, itemNo, &itemType, &item, &box);
- GetPort(&curPort);
- SetPort(theWindow);
- oldFont = theWindow->txFont;
- oldSize = theWindow->txSize;
- TextFont(kFontIDGeneva);
- TextSize(9);
- BlockMove(gSelectSpec.name + 1, s + 47, gSelectSpec.name[0]);
- sLength += gSelectSpec.name[0];
- s[sLength] = '”';
- sLength++;
- TETextBox(s, sLength, &box, teJustLeft);
- TextFont(oldFont);
- TextSize(oldSize);
- SetPort(curPort);
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // DrawDefaultButton
- //
- // Draws outline around default button
- //
- static pascal void DrawDefaultButton(
- WindowPtr theWindow,
- SInt16 itemNo)
- {
- WindowPtr curPort;
- Handle item;
- PenState curPen;
- Rect box;
- SInt16 itemType;
- SInt16 buttonOval;
-
- GetDialogItem(theWindow, itemNo, &itemType, &item, &box);
- GetPort(&curPort);
- SetPort(theWindow);
- GetPenState(&curPen);
- PenNormal();
-
- PenPat(& qd.black);
- PenSize(3, 3);
- buttonOval = ((box.bottom - box.top) / 2) + 2;
- FrameRoundRect(&box, buttonOval, buttonOval);
-
- SetPenState(& curPen);
- SetPort(curPort);
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // SaveWindowPos
- //
- // Save the window position in prefs.
- //
- OSErr SaveWindowPos (
- WindowPtr pWin)
- {
- Handle h;
- Rect winRect;
- FSSpec prefsSpec;
- SInt32 dirID;
- SInt16 fileRef, volumeRef;
- OSErr err;
-
- winRect = (**(((WindowPeek) pWin)->contRgn)).rgnBBox;
-
- // find the preferences folder
- err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &volumeRef, &dirID);
- if (err != noErr)
- return err;
-
- // open the preferences file
- h = Get1Resource('STR ', kPrefsFileResourceID);
- if (h == nil)
- return ResError();
- DetachResource(h);
- HLock(h);
- err = FSMakeFSSpec(volumeRef, dirID, (ConstStr255Param) *h, &prefsSpec);
- HUnlock(h);
- DisposeHandle(h);
- if (err == noErr)
- {
- fileRef = FSpOpenResFile(&prefsSpec, fsRdWrPerm);
- err = ResError();
-
- if (err == noErr)
- {
- // setup the preferences flags
- h = Get1Resource('win ', kWinPosPrefsID);
- if (h == nil)
- {
- h = NewHandle(sizeof(Rect));
- **((Rect **) h) = winRect;
- AddResource(h, kWinPosPrefsType, kWinPosPrefsID, nil);
- UpdateResFile(fileRef);
- ReleaseResource(h);
- }
- else
- {
- **((Rect **) h) = winRect;
- ChangedResource(h);
- ReleaseResource(h);
- }
- CloseResFile(fileRef);
- }
- }
- return err;
- }
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // GetWindowPos
- //
- // Retrieves the window position in prefs.
- //
- OSErr GetWindowPos (
- Rect *r)
- {
- Handle h;
- FSSpec prefsSpec;
- SInt32 dirID;
- SInt16 fileRef, volumeRef;
- OSErr err;
-
- // find the preferences folder
- err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &volumeRef, &dirID);
- if (err != noErr)
- return err;
-
- // open the preferences file
- h = Get1Resource('STR ', kPrefsFileResourceID);
- if (h == nil)
- return ResError();
- DetachResource(h);
- HLock(h);
- err = FSMakeFSSpec(volumeRef, dirID, (ConstStr255Param) *h, &prefsSpec);
- HUnlock(h);
- DisposeHandle(h);
- if (err == noErr)
- {
- fileRef = FSpOpenResFile(&prefsSpec, fsRdPerm);
- err = ResError();
-
- if (err == noErr)
- {
- // setup the preferences flags
- h = Get1Resource('win ', kWinPosPrefsID);
- if (h == nil)
- {
- err = resNotFound;
- }
- else
- {
- *r = **((Rect **) h);
- ReleaseResource(h);
- }
- CloseResFile(fileRef);
- }
- }
- return err;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // InitPrefs
- //
- // Read the preferences from the prefs file or create it if it does not exist
- //
- OSErr InitPrefs (void)
- {
- Handle h;
- Str63 menuString;
- FSSpec prefsSpec;
- SInt32 dirID;
- SInt16 vRefNum;
- SInt16 fileRefNum;
- SInt16 oldResFile;
- OSErr err;
- Boolean needsUpdate;
-
- // find the preferences folder
- err = FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, &vRefNum, &dirID);
- if (err != noErr)
- return err;
-
- // create the preferences file if it does not exist
- h = Get1Resource('STR ', kPrefsFileResourceID);
- if (h == nil)
- return ResError();
- DetachResource(h);
- HLock(h);
- err = FSMakeFSSpec(vRefNum, dirID, (ConstStr255Param) *h, &prefsSpec);
- HUnlock(h);
- DisposeHandle(h);
- if (err == fnfErr)
- {
- FSpCreateResFile(&prefsSpec, 'fwfx', 'pref', smSystemScript);
- err = ResError();
- if (err != noErr)
- return err;
- }
-
- oldResFile = CurResFile();
- fileRefNum = FSpOpenResFile(&prefsSpec, fsRdWrPerm);
- err = ResError();
- if (err != noErr)
- {
- // file may exist but have no resource fork, create one and open it
- FSpCreateResFile(&prefsSpec, 'fwfx', 'pref', smSystemScript);
- err = ResError();
- if (err != noErr)
- return err;
- fileRefNum = FSpOpenResFile(&prefsSpec, fsRdWrPerm);
- err = ResError();
- if (err != noErr)
- return err;
- }
-
- // setup the preferences flags
- h = Get1Resource(kPrefsResourceType, kPrefsResourceID);
- if (h == nil)
- {
- h = NewHandle(4);
- **((UInt32 **) h) = gpFWXAppData->fwixPrefs = 1;
- AddResource(h, kPrefsResourceType, kPrefsResourceID, nil);
- UpdateResFile(fileRefNum);
- ReleaseResource(h);
- }
- else
- {
- gpFWXAppData->fwixPrefs = **((UInt32 **) h);
- ReleaseResource(h);
- }
-
- // setup the notification sound preferences
- h = Get1Resource('STR ', kSndPrefsResourceID);
- if (h == nil)
- {
- UseResFile(oldResFile);
- h = Get1Resource('STR ', kSndPrefsResourceID);
- if (h == nil)
- return ResError();
- DetachResource(h);
- UseResFile(fileRefNum);
- AddResource(h, 'STR ', kSndPrefsResourceID, nil);
- UpdateResFile(fileRefNum);
- BlockMove(*h, gpFWXAppData->fwixNotifySound, **h + 1);
- ReleaseResource(h);
- }
- else
- {
- BlockMove(*h, gpFWXAppData->fwixNotifySound, **h + 1);
- ReleaseResource(h);
- }
-
- // setup receive folder
- h = Get1Resource(rAliasType, kDropPrefsResourceID);
- if (h == nil)
- {
- // retrieve receive folder name
- UseResFile(oldResFile);
- h = Get1Resource('STR ', kDropPrefsResourceID);
- if (h == nil)
- return ResError();
- FindFolder(kOnSystemDisk, kDesktopFolderType, kDontCreateFolder, &vRefNum, &dirID);
- DetachResource(h);
- HLock(h);
- err = FSMakeFSSpec(vRefNum, dirID, (ConstStr255Param) *h, &gpFWXAppData->fwixReceiveFolder);
- if (err == fnfErr)
- err = FSpDirCreate(&gpFWXAppData->fwixReceiveFolder, smSystemScript, &dirID);
- HUnlock(h);
- DisposeHandle(h);
-
- // update the resource
- err = NewAliasMinimal(&gpFWXAppData->fwixReceiveFolder, (AliasHandle *) &h);
- UseResFile(fileRefNum);
- AddResource(h, rAliasType, kDropPrefsResourceID, nil);
- UpdateResFile(fileRefNum);
- ReleaseResource(h);
- }
- else
- {
- // got alias, try to resolve it
- DetachResource(h);
- err = ResolveAlias(nil, (AliasHandle) h, &gpFWXAppData->fwixReceiveFolder, &needsUpdate);
- if ((err != noErr) && (err != fnfErr))
- {
- // can't resolve alias, re-init receive folder preferences
- DisposeHandle(h);
-
- UseResFile(oldResFile);
- h = Get1Resource('STR ', kDropPrefsResourceID);
- if (h == nil)
- return ResError();
- FindFolder(kOnSystemDisk, kDesktopFolderType, kDontCreateFolder, &vRefNum, &dirID);
- DetachResource(h);
- HLock(h);
- err = FSMakeFSSpec(vRefNum, dirID, (ConstStr255Param) *h, &gpFWXAppData->fwixReceiveFolder);
- if (err == fnfErr)
- err = noErr;
- HUnlock(h);
- DisposeHandle(h);
-
- // update the resource
- err = NewAliasMinimal(&gpFWXAppData->fwixReceiveFolder, (AliasHandle *) &h);
- UseResFile(fileRefNum);
- AddResource(h, rAliasType, kDropPrefsResourceID, nil);
- UpdateResFile(fileRefNum);
- ReleaseResource(h);
- }
- else if (needsUpdate)
- {
- AddResource(h, rAliasType, kDropPrefsResourceID, nil);
- UpdateResFile(fileRefNum);
- ReleaseResource(h);
- }
- }
- CloseResFile(fileRefNum);
- FlushVol(nil, vRefNum);
- UseResFile(oldResFile);
-
- // make sure receive folder exists and update open receive folder menu string
- err = FSpDirCreate(&gpFWXAppData->fwixReceiveFolder, smSystemScript, &dirID);
- if (err == dupFNErr)
- err = noErr;
-
- GetMenuItemText(GetMenuHandle(kFileMenuID), kOpenDropMenuItem, menuString);
- BlockMove (gpFWXAppData->fwixReceiveFolder.name + 1,
- menuString + 7,
- gpFWXAppData->fwixReceiveFolder.name[0]);
- menuString[0] = 6 + gpFWXAppData->fwixReceiveFolder.name[0] + 1;
- menuString[menuString[0]] = '”';
- SetMenuItemText(GetMenuHandle(kFileMenuID), kOpenDropMenuItem, menuString);
-
- return err;
- }
-